/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAL;

import DTO.DTOExport;
import DTO.DTOInventory;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author Pham
 */
public class DALExport {
    ConnectionDB conn;
    
    public DALExport()
    {
        conn = new ConnectionDB();
    }
    
    //method get all export
    public ArrayList<DTOExport> getExports()
    {
        try
        {
            ArrayList<DTOExport> listExp = new ArrayList<>();
            String querySelect = "select * from `export`";
            ResultSet rs = conn.executeQuery(querySelect);
            while(rs.next())
            {
                listExp.add(new DTOExport(rs));
            }
            return listExp;
        }
        catch(Exception ex)
        {
            System.err.printf(ex.getMessage());
            return null;
        }
    }
    
    //method get export by id
    public DTOExport getExportbyId(String expId)
    {
        try{
            DTOExport dtoExp = null;
            String query = "select * from  `export` where export_id = '"+ expId +"'";
            ResultSet rs = conn.executeQuery(query);
            while(rs.next())
            {
                dtoExp = new DTOExport(rs);
            }
            return dtoExp;
        }
        catch(Exception ex){
            System.err.printf(ex.getMessage());
            return null;
        }
    }
    
    //method create new export
    public boolean createNewExport(DTOExport dtoExp)
    {
        try{
            String queryInsert = "insert into `export`(`export_id`, `export_date`, `order_id`) values('"+dtoExp.getExportId()+"', '"+dtoExp.getExportDate()+"', "
                                + " '"+ dtoExp.getDtoOrder().getOrderId() +"')";
            if(conn.exeUpdate(queryInsert))
                return true;
            return false;
        }
        catch(Exception ex)
        {
            System.err.printf(ex.getMessage());
            return false;
        }
    }
}
